/**
 * 职位
 */
import request from '@/utils/request';
import type { ApiResult } from '@/api';
import type { Position, PositionParam } from './model';

/**
 * 列表
 */
export async function list(params?: PositionParam) {
  const res = await request.get<ApiResult<Position[]>>('/sysPos/list', {
    params
  });
  if (res.data.code === 200) {
    return res.data.result;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加
 */
export async function add(data: Position) {
  const res = await request.post<ApiResult<unknown>>('/sysPos/add', data);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改
 */
export async function update(data: Position) {
  const res = await request.post<ApiResult<unknown>>('/sysPos/update', data);
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除
 */
export async function remove(id?: number) {
  const res = await request.post<ApiResult<unknown>>('/sysPos/delete/', {
    id
  });
  if (res.data.code === 200) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
